#include <cppunit/config/SourcePrefix.h>
#include "TestUses.h"
#include <string>

void TestUses::setUp() {
}

void TestUses::tearDown() {
}

CPPUNIT_TEST_SUITE_REGISTRATION( TestUses );

void TestUses::testAddGetUsesStatement(){
	Uses uses = Uses();
	uses.addUsesStatement(1, 1);
	uses.addUsesStatement(1, 2);
	uses.addUsesStatement(2, 1);
	uses.addUsesStatement(4, 3);
	uses.addUsesStatement(4, 2);
	uses.addUsesStatement(4, 1);
	uses.addUsesStatement(10, 2);
	uses.addUsesStatement(11, 2);
	uses.addUsesStatement(13, 4);
	uses.addUsesStatement(13, 5);

	vector<pair<int,int>> anyany = uses.getUsesStatement(ANYVALUE, ANYVALUE);
	int size = anyany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("All results return", 10, size);

	vector<pair<int,int>> anynum = uses.getUsesStatement(ANYVALUE, 1);
	size = anynum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("3 results found", 3, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (1,1)", 1, anynum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (2,1)", 2, anynum.at(1).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("third result (4,1)", 4, anynum.at(2).first);

	vector<pair<int,int>> numany = uses.getUsesStatement(4, ANYVALUE);
	size = numany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("3 results found", 3, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (4,1)", 1, numany.at(0).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (4,2)", 2, numany.at(1).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("third result (4,3)", 3, numany.at(2).second);

	vector<pair<int,int>> numnum = uses.getUsesStatement(13, 4);
	size = numnum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("1 result found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (13,4)", 13, numnum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (13,4)", 4, numnum.at(0).second);

	vector<pair<int,int>> none = uses.getUsesStatement(3, 3);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("no result found", 0, size);
}

void TestUses::testAddGetUsesProcedure(){
	Uses uses = Uses();
	uses.addUsesProcedure(0, 1);
	uses.addUsesProcedure(0, 2);
	uses.addUsesProcedure(0, 3);
	uses.addUsesProcedure(1, 1);
	uses.addUsesProcedure(1, 2);
	uses.addUsesProcedure(1, 4);
	uses.addUsesProcedure(1, 6);

	vector<pair<int,int>> anyany = uses.getUsesProcedure(ANYVALUE, ANYVALUE);
	int size = anyany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("All results return", 7, size);

	vector<pair<int,int>> anynum = uses.getUsesProcedure(ANYVALUE, 1);
	size = anynum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("2 results found", 2, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (0,1)", 0, anynum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (1,1)", 1, anynum.at(1).first);

	vector<pair<int,int>> numany = uses.getUsesProcedure(1, ANYVALUE);
	size = numany.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("4 results found", 4, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("first result (1,1)", 1, numany.at(0).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("second result (1,2)", 2, numany.at(1).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("third result (1,4)", 4, numany.at(2).second);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("fourth result (1,6)", 6, numany.at(3).second);

	vector<pair<int,int>> numnum = uses.getUsesProcedure(1, 6);
	size = numnum.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("1 result found", 1, size);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (1,6)", 1, numnum.at(0).first);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("one result (1,6)", 6, numnum.at(0).second);

	vector<pair<int,int>> none = uses.getUsesProcedure(0, 6);
	size = none.size();
	CPPUNIT_ASSERT_EQUAL_MESSAGE("no result found", 0, size);
}
